home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / share / audacity / nyquist / stk.lsp < prev    next >
Encoding:
Lisp/Scheme  |  2010-09-21  |  6.7 KB  |  190 lines

  1. ;; stk.lsp -- STK-based instruments
  2. ;;
  3. ;; currently clarinet and saxophony are implemented
  4.  
  5. (defun instr-parameter (parm)
  6.   ;; coerce parameter into a *sound-srate* signal
  7.   (cond ((numberp parm)
  8.          (stretch 30 (control-srate-abs *sound-srate* (const (float parm)))))
  9.         (t
  10.          (force-srate *sound-srate* parm))))
  11.  
  12.  
  13. (defun clarinet (step breath-env)
  14.   (snd-clarinet (step-to-hz step) (force-srate *sound-srate* breath-env) *sound-srate*))
  15.  
  16.  
  17. (defun clarinet-freq (step breath-env freq-env)
  18.   ;; note that the parameters are in a different order -- I defined 
  19.   ;; clarinet-freq this way so that the first two parameters are always
  20.   ;; step and breath. I didn't redo snd-clarinet-freq.
  21.   (snd-clarinet_freq (step-to-hz step) 
  22.                 (instr-parameter breath-env)
  23.                 (instr-parameter freq-env)
  24.                 *sound-srate*))
  25.  
  26.  
  27.  
  28. (defun clarinet-all (step breath-env freq-env vibrato-freq vibrato-gain reed-stiffness noise)
  29.   ;; note that the parameters are not in the same order as snd-clarinet-all
  30.   (setf breath-env (instr-parameter breath-env))
  31.   (setf freq-env (instr-parameter freq-env))
  32.   (setf reed-stiffness (instr-parameter reed-stiffness))
  33.   (setf noise (instr-parameter noise))
  34.   (snd-clarinet_all (step-to-hz step)
  35.                     breath-env freq-env 
  36.                     ;; STK scales 1.0 to 12Hz. Scale here so vibrato-freq is in Hz
  37.                     (/ vibrato-freq 12.0) vibrato-gain
  38.                     reed-stiffness noise 
  39.                     *sound-srate*))
  40.  
  41.  
  42. (defun sax (step breath-env)
  43.   (snd-sax (step-to-hz step) (force-srate *sound-srate* breath-env) *sound-srate*))
  44.  
  45. (defun sax-freq (step breath-env freq-env)
  46.   (snd-sax_freq (step-to-hz step)
  47.           (instr-parameter breath-env)
  48.           (instr-parameter freq-env)
  49.           *sound-srate*))
  50.  
  51. (defun sax-all (step breath-env freq-env vibrato-freq vibrato-gain reed-stiffness noise blow-pos reed-table-offset)
  52.   (snd-sax_all (step-to-hz step)
  53.            (instr-parameter freq-env)
  54.                (instr-parameter breath-env)
  55.                (instr-parameter (/ vibrato-freq 12.0))
  56.                (instr-parameter vibrato-gain)
  57.                (instr-parameter reed-stiffness)
  58.                (instr-parameter noise)
  59.                (instr-parameter blow-pos)
  60.                (instr-parameter reed-table-offset)
  61.                *sound-srate*)
  62. )
  63.  
  64. ; instr-parameter already defined in stk.lsp
  65.  
  66. (defun flute (step breath-env)
  67.   (snd-flute (step-to-hz step) (force-srate *sound-srate* breath-env) *sound-srate*))
  68.  
  69. (defun flute-freq (step breath-env freq-env)
  70.   (snd-flute_freq (step-to-hz step) 
  71.           (instr-parameter breath-env)
  72.           (instr-parameter freq-env)
  73.           *sound-srate*))
  74.  
  75. (defun flute-all (step breath-env freq-env vibrato-freq vibrato-gain jet-delay noise)
  76.   ;; note that the parameters are not in the same order as snd-clarinet-all
  77.   (setf breath-env (instr-parameter breath-env))
  78.   (setf freq-env (instr-parameter freq-env))
  79.   (setf jet-delay (instr-parameter jet-delay))
  80.   (setf noise (instr-parameter noise))
  81.   (snd-flute_all (step-to-hz step)
  82.                     breath-env freq-env 
  83.                     ;; STK scales 1.0 to 12Hz. Scale here so vibrato-freq is in Hz
  84.                     (/ vibrato-freq 12.0) vibrato-gain
  85.                     jet-delay noise 
  86.                     *sound-srate*))
  87.  
  88.  
  89. (defun bowed (step bowpress-env)
  90.   (snd-bowed (step-to-hz step) (force-srate *sound-srate* bowpress-env) *sound-srate*))
  91.  
  92. (defun bowed-freq (step bowpress-env freq-env)
  93.   (snd-bowed_freq (step-to-hz step)
  94.           (instr-parameter bowpress-env)
  95.           (instr-parameter freq-env)
  96.           *sound-srate*))
  97.  
  98. (defun mandolin (step dur &optional (detune 4.0))
  99.   (let ((d (get-duration dur)))
  100.     (snd-mandolin *rslt* (step-to-hz step) d 1.0 detune *sound-srate*)))
  101.  
  102. (defun wg-uniform-bar (step bowpress-env)
  103.   (snd-bandedwg (step-to-hz step) (force-srate *sound-srate* bowpress-env) 0 *sound-srate*))
  104.  
  105. (defun wg-tuned-bar (step bowpress-env)
  106.   (snd-bandedwg (step-to-hz step) (force-srate *sound-srate* bowpress-env) 1 *sound-srate*))
  107.  
  108. (defun wg-glass-harm (step bowpress-env)
  109.   (snd-bandedwg (step-to-hz step) (force-srate *sound-srate* bowpress-env) 2 *sound-srate*))
  110.  
  111. (defun wg-tibetan-bowl (step bowpress-env)
  112.   (snd-bandedwg (step-to-hz step) (force-srate *sound-srate* bowpress-env) 3 *sound-srate*))
  113.  
  114. (defun modalbar (preset step duration)
  115.    (let ((preset (case preset
  116.             (MARIMBA 0)
  117.             (VIBRAPHONE 1)
  118.             (AGOGO 2)
  119.             (WOOD1 3)
  120.             (RESO 4)
  121.             (WOOD2 5)
  122.             (BEATS 6)
  123.             (TWO-FIXED 7)
  124.             (CLUMP 8)
  125.             (t (error (format nil "Unknown preset for modalbar %A" preset)))))
  126.      (d (get-duration duration)))
  127.      (snd-modalbar *rslt* (step-to-hz step) preset d *sound-srate*)))
  128.  
  129. (defun sitar (step dur)
  130.   (let ((d (get-duration dur)))
  131.     (snd-sitar *rslt* (step-to-hz step) d *sound-srate*)))
  132.  
  133. (defun nyq:nrev (snd rev-time mix)
  134.   (snd-stkrev 0 snd rev-time mix *sound-srate*))
  135.  
  136. (defun nyq:jcrev (snd rev-time mix)
  137.   (snd-stkrev 1 snd rev-time mix *sound-srate*))
  138.  
  139. (defun nyq:prcrev (snd rev-time mix)
  140.   (snd-stkrev 2 snd rev-time mix *sound-srate*))
  141.  
  142. (defun nrev (snd rev-time mix)
  143.   (multichan-expand #'nyq:nrev snd rev-time mix))
  144.  
  145. (defun jcrev (snd rev-time mix)
  146.   (multichan-expand #'nyq:jcrev snd rev-time mix))
  147.  
  148. (defun prcrev (snd rev-time mix)
  149.   (multichan-expand #'nyq:prcrev snd rev-time mix))
  150.  
  151. (defun nyq:chorus (snd depth freq mix &optional (base-delay 6000))
  152.   (snd-stkchorus snd base-delay depth freq mix *sound-srate*))
  153.  
  154. (defun stkchorus (snd depth freq mix &optional (base-delay 6000))
  155.   (multichan-expand #'nyq:chorus snd depth freq mix base-delay))
  156.  
  157. (defun nyq:pitshift (snd shift mix)
  158.   (snd-stkpitshift snd shift mix *sound-srate*))
  159.  
  160. (defun pitshift (snd shift mix)
  161.   (multichan-expand #'nyq:pitshift snd shift mix))
  162.  
  163.  
  164.  
  165. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  166. ; HELPER FUNCTIONS
  167. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  168. ; pass in rates of increase/decrease in begin/end... this is like noteOn and noteOff
  169. ;
  170. ; STK uses setRate but the actual ramp time is also a function of the sample rate.
  171. ; I will assume the clarinet was run at 44100Hz and fix things so that the envelope
  172. ; is sample-rate independent.
  173. ;
  174. ; STK seemed to always give a very fast release, so I changed the numbers so that
  175. ; note-off values from 0.01 to 1 give an interesting range of articulations.
  176. ;
  177. ; IMPORTANT: the returned envelope is 0.1s longer than dur. There is 0.1s of silence
  178. ; at the end so that the clarinet can "ring" after the driving force is removed.
  179. ;
  180. (defun stk-breath-env (dur note-on note-off)
  181.   (let* ((target (+ 0.55 (* 0.3 note-on)))
  182.          (on-time (/ (* target 0.0045) note-on))
  183.          (off-time (/ (* target 0.02) note-off)))
  184.     ;(display "clarinet-breath-env" target on-time off-time)
  185.     (pwl on-time target
  186.          (- dur off-time) target
  187.          dur 0 (+ dur 0.1))))
  188.  
  189.  
  190.